home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Programming / LEDA / incl / LEDA.020+881 / int_set.h < prev    next >
C/C++ Source or Header  |  1994-08-05  |  2KB  |  81 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  int_set.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_INTSET_H
  16. #define LEDA_INTSET_H
  17.  
  18. //------------------------------------------------------------------------------
  19. /* int_set: integer sets implemented by bit vectors                           */
  20. //------------------------------------------------------------------------------
  21.  
  22. #include <LEDA/basic.h>
  23.  
  24. class int_set {
  25.  
  26. unsigned long*  V;
  27. int size;
  28. int low;
  29.  
  30. public:
  31.  
  32.  int_set(int n); 
  33.  int_set(int,int); 
  34.  int_set(const int_set&);
  35. ~int_set() { delete V; } 
  36.  
  37.  
  38. void clear();
  39. void insert(int);
  40. void del(int);
  41.  
  42. int  member(int) const;
  43.  
  44. int_set& join(const int_set&);
  45. int_set& intersect(const int_set&);
  46. int_set& complement();
  47.  
  48. int_set& operator=(const int_set&);
  49.  
  50. int_set& operator|=(const int_set&);
  51. int_set& operator&=(const int_set&);
  52.  
  53. int_set  operator|(const int_set&);
  54. int_set  operator&(const int_set&);
  55. int_set  operator~();
  56.  
  57. };
  58.  
  59. inline int  int_set::member(int x)  const
  60. { int i = x-low; 
  61.   return V[i/32] & (1 << (i%32)); 
  62.  }
  63.  
  64. inline void int_set::insert(int x) 
  65. { int i  =  x-low; 
  66.   V[i/32] |= (1 << (i%32)); 
  67.  }
  68.  
  69. inline void int_set::del(int x)    
  70. { int i   = x-low; 
  71.   V[i/32] &= ~(1 << (i%32)); 
  72.  }
  73.  
  74. inline int_set& int_set::operator|=(const int_set& s) { return join(s); }
  75.  
  76. inline int_set& int_set::operator&=(const int_set& s) { return intersect(s); }
  77.  
  78.  
  79. #endif
  80.